import Config from "./Config";

export default class GameModel {
   public win: boolean = false;

   private _preciseLevel: number = 19
   private _dropLevel: number = 1
   private _dragLevel: number = 1
   private _drawLevel: number = 1
   private _tipCount:number=1;

   public selectedModel: number = 1 //精确 掉落 拖曳
   public selectedLevel: number = 18
   public getStar: number = 0

   public drawComplete: boolean = false;
   public dragComplete: boolean = false;
   public dropComplete: boolean = false;
   public preciseComplete: boolean = false;
   public completeInfo = []
   public drawLevelInfo: Array<number> = [];
   public isNull(str) {
      if (str != null && str != undefined && str != '' && str != NaN) {
         return false
      }
      return true
   }
   readDraw() {
      //画线关卡数据
      var drawLevelStr = cc.sys.localStorage.getItem('drawLevelInfo')
      if (!this.isNull(drawLevelStr)) {

         this.drawLevelInfo = [];
         var list = drawLevelStr.split(',')
         for (var i = 0; i < list.length; i++) {
            this.drawLevelInfo.push(parseInt(list[i]));
         }
      } else {
         this.drawLevelInfo = [-1];
      }
      for (var m = 0; m < this.drawLevelInfo.length; m++) {
         if (this.drawLevelInfo[m] == -1) {
            this._drawLevel = m + 1
            break;
         }
      }
      //是否完成
      var lInfo = cc.sys.localStorage.getItem('completeInfo')
      if (!this.isNull(lInfo)) {
         var list = lInfo.split(',')
         for (var i = 0; i < list.length; i++) {
            this.completeInfo.push(parseInt(list[i]));
         }
      } else {
         this.completeInfo = [0, 0, 0, 0]
      }
      //提示数量
      var tipStr = cc.sys.localStorage.getItem('tipCount')
      if (!this.isNull(tipStr)) {
         this._tipCount=parseInt(tipStr)
      } else {
         this._tipCount=2
      }

   }
   saveDraw() {
      var s = this.drawLevelInfo.join(',')
      cc.sys.localStorage.setItem('drawLevelInfo', s)

   }
   set preciseLevel(value: number) {
      if (value > Config.preciseLevels.length - 1) {
         console.log('通关');
         value = 1;
         this.completeInfo[0] = 1
         cc.sys.localStorage.setItem('completeInfo', this.completeInfo.join(','))
      }
      this._preciseLevel = value;
      cc.sys.localStorage.setItem('preciseLevel', value + '')

   }
   get preciseLevel() {
      return this._preciseLevel
   }

   set dragLevel(value: number) {
      if (value > Config.dragLevels.length - 1) {
         console.log('通关');
        // value = 1;
         this.completeInfo[2] = 1
         cc.sys.localStorage.setItem('completeInfo', this.completeInfo.join(','))
      }
      this._dragLevel = value;
      cc.sys.localStorage.setItem('dragLevel', value + '')
   }
   get dragLevel() {
      return this._dragLevel
   }
   set dropLevel(value: number) {
      if (value > Config.brickLevels.length - 1) {
         console.log('通关');
       //  value = 1;
         this.completeInfo[1] = 1
         cc.sys.localStorage.setItem('completeInfo', this.completeInfo.join(','))
      }
      this._dropLevel = value;
      cc.sys.localStorage.setItem('dropLevel', value + '')
   }
   get dropLevel() {
      return this._dropLevel
   }
   set drawLevel(value: number) {
      if (value > Config.drawLevels.length - 1) {
         console.log('通关');
       //  value = 1;
         this.completeInfo[3] = 1
         cc.sys.localStorage.setItem('completeInfo', this.completeInfo.join(','))
      }
      this._drawLevel = value;
      //  cc.sys.localStorage.setItem('drawLevel', value + '')
   }
   get drawLevel() {
      return this._drawLevel
   }

   get tipCount() {
      return this._tipCount
   }
   set tipCount(value: number) {
      this._tipCount=value
      cc.sys.localStorage.setItem('tipCount', value + '')
   }
}
